package pers.cz.jefconfig.resource;

import pers.cz.jefconfig.log.LogUtils;

import java.net.URL;

/**
 * @program: JefConfig
 * @description:
 * @author: Cheng Zhi
 * @create: 2022-07-15 15:10
 **/
public abstract class Resource {

    protected URL url;

    public static FileResource DUMMY;

    public Resource(URL url) {
        this.url = url;
    }

    public static FileResource getFileResource(URL url) {
        if (url == null)
            return DUMMY;

        String p = url.getProtocol();
        if ("file".equals(p)) {
            return new FileResource(url);
        } else if ("jar".equals(p) || "zip".equals(p)) {
            return new ZipFileResource(url);
        } else {
            LogUtils.warn("不能识别的文件协议");
        }

        return null;
    }

}
